package com.snap.awesomeserial.model;

import com.snap.awesomeserial.bean.TemplateEntity;

import org.litepal.crud.callback.FindMultiCallback;
import org.litepal.crud.callback.SaveCallback;
import org.litepal.crud.callback.UpdateOrDeleteCallback;

public class DBManager {

    private static final String TAG = "DBManager";

    private static DBManager dbManager;
    private DBModel dbModel;
    private static final Object OBJECT = new Object();

    public synchronized static DBManager get() {
        if (dbManager == null) {
            synchronized (OBJECT) {
                if (null == dbManager) {
                    dbManager = new DBManager();
                }
            }
        }
        return dbManager;
    }

    private DBManager() {
        dbModel = new DBModel();
    }


    //=============================👇模板👇==================================
    //保存模板
    public void saveDemo(TemplateEntity demo, SaveCallback callback) {
        dbModel.saveDemo(demo, callback);
    }

    //获取所有模板
    public void getAllDemo(FindMultiCallback<TemplateEntity> callback) {
        dbModel.getDemoList(Integer.MAX_VALUE, callback);
    }

    //获取首页模板
    public void getPartDemo(FindMultiCallback<TemplateEntity> callback) {
        dbModel.getDemoList(4, callback);
    }

    //删除模板
    public void deleteDemo(UpdateOrDeleteCallback callback, String... demoID) {
        dbModel.deleteDemo(callback, demoID);
    }

}
